home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / fullr_2 / gfxmisc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-29  |  2.3 KB  |  147 lines

  1. #include <conio.h>
  2. #include <dos.h>
  3. #include <memory.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <pc.h>
  7.  
  8. #include "gfxmisc.h"
  9.  
  10. long *cosTab;
  11. long *sinTab;
  12. long *scaleTab;
  13. long *yTab;
  14. long startingPointU[256];
  15. long startingPointV[256];
  16.  
  17. void
  18. gfxSetMode(int mode)
  19. {
  20.     union REGS r;
  21.  
  22.     r.x.ax = mode;
  23.  
  24.     int86(0x10, &r, &r);
  25. }
  26.  
  27.  
  28. void
  29. gfxExtendMode(void)
  30. {
  31.     outportb(0x3C2, 0xE3);
  32. }
  33.  
  34.  
  35. void
  36. gfxSetPalette(unsigned char *palette)
  37. {
  38.     int i;
  39.  
  40.     outportb(0x03c8, 0);
  41.  
  42.     i = 256;
  43.     while (i--) {
  44.         outportb(0x03c9, *palette++);
  45.         outportb(0x03c9, *palette++);
  46.         outportb(0x03c9, *palette++);
  47.     }
  48. }
  49.  
  50.  
  51. char *
  52. gfxLoadPCX(char *pcxFName, char *image)
  53. {
  54.     FILE *fp;
  55.     int size, i;
  56.     unsigned char PCX_byte, RLE_byte;
  57.     unsigned char *buf_ptr;
  58.     unsigned char *end_of_buf;
  59.     unsigned char palette[768];
  60.  
  61.     fp = fopen(pcxFName, "rb");
  62.  
  63.     if (fp == NULL) {
  64.         return NULL;
  65.     } else {
  66.         fseek(fp, 8, SEEK_SET);
  67.         size = 64000;
  68.  
  69.         image = (char *) malloc(size);
  70.         buf_ptr = image;
  71.         end_of_buf = buf_ptr + size;
  72.  
  73.         fseek(fp, -768, SEEK_END);
  74.         fread(palette, 1, 768, fp);
  75.         for (i=0; i < 768; i++) {
  76.             palette[i] = palette[i] >> 2;
  77.         }
  78.  
  79.         fseek(fp, 128, SEEK_SET);
  80.  
  81.         while (buf_ptr < end_of_buf) {
  82.             fread(&PCX_byte, 1, 1, fp);
  83.  
  84.             if (PCX_byte < 192) {
  85.                 *buf_ptr++ = PCX_byte;
  86.             } else {
  87.                 PCX_byte = PCX_byte & 0x3F;
  88.                 fread(&RLE_byte, 1, 1, fp);
  89.                 memset(buf_ptr, RLE_byte, PCX_byte);
  90.                 buf_ptr += PCX_byte;
  91.             }
  92.         }
  93.  
  94.         fclose(fp);
  95.  
  96.         gfxSetPalette(palette);
  97.  
  98.         return image;
  99.     }
  100.  
  101. }
  102.  
  103.  
  104. void
  105. gfxInitTables(void)
  106. {
  107.     FILE *fp;
  108.     int i;
  109.     unsigned long dU, dV;
  110.  
  111.     sinTab = (long *) malloc(256 * 4);
  112.     cosTab = (long *) malloc(256 * 4);
  113.     scaleTab = (long *) malloc(128 * 4);
  114.     yTab     = (long *) malloc(200 * 4);
  115.  
  116.     fp = fopen("sintab.dat", "rb");
  117.     fread(sinTab, 4, 256, fp);
  118.     fread(cosTab, 4, 256, fp);
  119.     fclose(fp);
  120.  
  121.     for (i=0; i < 200; i++) {
  122.         yTab[i] = i * 320;
  123.     }
  124.  
  125.     for (i=0; i < 128; i++) {
  126.         scaleTab[i] = (i << 4);
  127.     }
  128.  
  129.     for (i=0; i<255; i++) {
  130.         dU = sinTab[i];
  131.         dV = cosTab[i];
  132.         startingPointU[i] = ((-160 * dV) + (100 * dU)) + (160 << 10);
  133.         startingPointV[i] = ((-160 * dU) - (100 * dV)) + (100 << 10);
  134.     }
  135. }
  136.  
  137.  
  138. void
  139. gfxCleanup(void)
  140. {
  141.     free(sinTab);
  142.     free(cosTab);
  143.     free(scaleTab);
  144.     free(yTab);
  145. }
  146.  
  147.